unit MuCharCompare;

interface

type
  MuCharCompareTool = class
    private
      muString,ziString:string;
    public
      constructor Create(mu,zi:string);overload;

      function Compare:Boolean;

      function AllCompare:Boolean;
  end;
implementation

{ MuCharCompareTool }

function MuCharCompareTool.AllCompare: Boolean;
var
 tempone,temptwo:string;
  I: Integer;
begin
  if Compare then
  begin
    Result:= True;
  end
  else
  begin
    for I := 0 to Length(muString) - 1 do
    begin
      tempone:=tempone + muString[Length(muString) - I];
    end;

    for I := 0 to Length(ziString) - 1 do
    begin
      temptwo:= temptwo+ ziString[Length(ziString) - I];
    end;

    muString:= tempone;
    ziString:= temptwo;

    if Compare then
    begin
      Result:= True;
    end else
    begin
      Result:= False;
    end;

  end
end;

function MuCharCompareTool.Compare: Boolean;
var
  I,J,startIndex:Integer;
  hasSame:Boolean;
begin
  I:= 1;
  J:=1;
  startIndex:=0;
  hasSame:=False;

  Result:= False;
  while (I <= Length(ziString)) and (J< Length(muString)) do
  begin
    if muString[J] = '*' then
    begin
       if hasSame then
       begin
         Result:= True;
         Exit;
       end;
    end;

    if (muString[J] = ziString[I]) or (muString[J]= '?') or (ziString[I] = '?') then
    begin
      if I = Length(ziString) then
      begin
        Result:= True;
        Exit;
      end;

      Inc(J);
      Inc(I);

      hasSame:= True;
    end
    else
    begin
      hasSame:= False;
      Inc(startIndex);

      J:= startIndex;
      I:= 1;
    end;

  end;
end;

constructor MuCharCompareTool.Create(mu, zi: string);
begin
  muString:= mu;
  ziString:= zi;
end;

end.
